<template>
  <div>
    <!-- 自定义 alert 对话框 -->
    <div v-if="isVisible" class="custom-alert">
      <div class="alert-content">{{ message }}</div>
      <button class="alert-btn" @click="closeAlert">确定</button>
    </div>

    <!-- 自定义遮罩层 -->
    <div v-if="isVisible" class="custom-overlay"></div>
  </div>
</template>

<script>
export default {
  name: 'CustomAlert',
  data() {
    return {
      isVisible: false, // 控制 alert 显示
      message: '',   // 保存 alert 消息内容
      address: '',//带地址跳转
      query: {}//带参数跳转
    };
  },
  methods: {
    showAlert(message, address) {
      this.message = message;  // 设置要显示的消息
      this.isVisible = true;    // 显示 alert
      this.address = address;
    },
    closeAlert() {
      this.isVisible = false;   // 隐藏 alert
      if (this.address != '' && this.query == '') {
        this.$router.push({ path: this.address });
      }
    }
  }
};
</script>

<style scoped>
.custom-alert {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: white;
  padding: 2vw;
  border: 0.1vw solid #ccc;
  box-shadow: 0vw 4vw 8vw rgba(0, 0, 0, 0.2);
  z-index: 9999;
  display: block;
  width: 60vw;
  text-align: center;
  justify-content: center;
  font-size: 4.6vw;
}

.custom-alert .alert-content {
  margin-top: 2vw;
  margin-bottom: 5vw;
}

.custom-alert .alert-btn {
  padding: 2vw 4vw;
  background-color: #007BFF;
  color: white;
  border: none;
  cursor: pointer;
  border-radius: 0.4vw;
  margin-bottom: 2vw;
  font-size: 4vw;
}

.custom-alert .alert-btn:hover {
  background-color: darkblue;
}

.custom-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 9998;
  display: block;
}
</style>